package com.cloudcc.mobile.view.fragment;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

import com.cloudcc.cloudframe.bus.IEventLife;
import com.cloudcc.cloudframe.ui.viewgroup.loadmore.LoadMoreContainer;
import com.cloudcc.cloudframe.ui.viewgroup.refresh.PtrFrameLayout;
import com.cloudcc.mobile.AppConfig;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.adapter.BeauListAdapterType.OnClickItem;
import com.cloudcc.mobile.adapter.BeauListAdapterType.onItemMenuClickListener;
import com.cloudcc.mobile.entity.beau.BeauListEntity;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.view.main.fragment.BaseListFragment;
import com.cloudcc.mobile.widget.listview.CloudCCListView;
import com.cloudcc.mobile.widget.listview.CloudCCListView.OnRefreshOrLoadMoreListener;
import com.mypage.adapter.ListViewAdapter;

public class XiangGuanFragment1 extends BaseListFragment implements IEventLife,
		onItemMenuClickListener, OnClickItem,
		 OnRefreshOrLoadMoreListener {
	private String mEns = RunTimeManager.getInstance().getlanguage();
	@Bind(R.id.xiangguanlistview)
	CloudCCListView mListView;
	ListViewAdapter  adapter;
	List<String> list = new ArrayList<String>();
	@Override
	public void init() {
		mListView.setOnRefreshOrLoadMoreListener(this);
		mListView.requestRefresh();
	}
	@Override
	public int getLayoutId() {
		return R.layout.xiangguanf1;
	}


	public void onLoadMore(LoadMoreContainer frame) {
		currentPage++;
		requestData();
	}
	@Override
	public void onRefresh(PtrFrameLayout frame) {
		
			list.clear();
			requestData();
		
	}
	
	@Override
	public void onClickItem(int pos, BeauListEntity t) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onClickPhone(int pos, BeauListEntity t) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onClickChatter(int pos, BeauListEntity t) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onClickEdit(int pos, BeauListEntity t) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onClickFollow(int pos, BeauListEntity t) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void register() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void unRegister() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void requestData() {
		// TODO Auto-generated method stub
		for (int i = 0; i < 20; i++) {
			list.add("数据："+i);
		}
		adapter = new ListViewAdapter(mContext, list);
		mListView.setAdapter(adapter);
		mListView.refreshComplete();
		onRequestFinish(true);
//		mListView.handlerLoadMoreFinish(true, false);
	}
	private void onRequestFinish(boolean dataIsEmpty) {
		if (isFromRefresh()) {// 第一次加载 并且数据出现空的话 就显示 空
			mListView.refreshComplete();
			mListView.handlerLoadMoreFinish(dataIsEmpty, !dataIsEmpty);// 第一次加载
		} else {
			mListView.refreshComplete();
			mListView.handlerLoadMoreFinish(false, !dataIsEmpty);// 不是来自刷新 是来自
																	// 上啦加载更多
																	// 这样的话
		}
	}
	/**
	 * 是不是 刷新加载的 或者第一次初始化加载
	 * 
	 * @return true 来自刷新的加载
	 */
	protected boolean isFromRefresh() {
		return currentPage <= AppConfig.DEFAULTPAGE;
	}

}
